package com.zhangchenhui.jmh;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

import static java.lang.Math.PI;
import static java.lang.Math.log;

/**
 * @author 张晨辉
 * @Classname JMHExample01
 * @Description TODO
 * @Date 2020/8/11 下午11:00
 */
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Mode.AverageTime)
@Threads(5)
@Fork(1)
@Measurement(iterations = 5)
@Warmup(iterations = 5)
@State(Scope.Benchmark)
public class JMHExample10 {

    @CompilerControl(CompilerControl.Mode.EXCLUDE)
    @Benchmark
    public void test(){

    }
    //禁止优化 不禁止优化最后跑出来的结果差不多
    @CompilerControl(CompilerControl.Mode.EXCLUDE)
    @Benchmark
    public void test1()  {
        log(PI) ;
    }

    public static void main(String[] args) throws RunnerException {
        final Options opts = new OptionsBuilder()
                .include(JMHExample10.class.getSimpleName())
                .build();
        new Runner(opts).run();


    }
}
